package com.gxa.autoparts.admin.controller;


import com.gxa.autoparts.admin.service.LogService;
import com.gxa.autoparts.core.common.JsonResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("/admin/log")
@RestController
@Transactional(rollbackFor = Throwable.class)
public class LogController {

    @Autowired
    private LogService logService;

    @ApiOperation("查询全部日志")
    @PostMapping("/findLog")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time1", value = "起始时间", required = false),
            @ApiImplicitParam(name = "time2", value = "截止时间", required = false),
            @ApiImplicitParam(name = "name", value = "操作员", required = false),
            @ApiImplicitParam(name = "type", value = "操作类型", required = false),
            @ApiImplicitParam(name = "page", value = "页数", required = true),
            @ApiImplicitParam(name = "size", value = "页内数据条数", required = true)
    })
    public Map findLog(String time1,String time2,String name,String type,Integer page,Integer size){
        List<Map> maps = logService.selectAllLog(time1, time2, name, type, (page - 1) * size, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(maps);
        jsonResult.put("totleNumber",logService.selectAllLog2(time1, time2, name, type).size());
        jsonResult.setMsg("查询全部日志成功");
        return jsonResult.getDataMap();
    }

    @ApiOperation("日志删除")
    @PostMapping("/deleteLogById")
    @ApiImplicitParam(name = "id", value = "日志Id", required = true)
    public Map deleteLogById(Long id){
        logService.deleteById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("日志删除成功");
        return jsonResult.getDataMap();
    }
}
